<script type="text/javascript" lang="javascript">
    dojo.require("dijit.MenuBar");
    dojo.require("dijit.PopupMenuBarItem");
    dojo.require("dijit.Menu");
    dojo.require("dijit.MenuItem");
    dojo.require("dijit.PopupMenuItem");
    dojo.require("dijit.form.Select");
    dojo.require("dijit.form.CheckBox");
    dojo.require("dijit.form.MultiSelect");
    dojo.require("dijit.ColorPalette");
</script>
<div dojoType="dijit.MenuBar" id="menuPrincipal">
    <div dojoType="dijit.PopupMenuBarItem">
        <span>
            SuiviDev
        </span>
        <div dojoType="dijit.Menu" id="suividevMenu">
            <div dojoType="dijit.MenuItem" onClick="window.location = '{% url developpements.views.home %}';">
                Accueil SuiviDev
            </div>
            <div dojoType="dijit.MenuItem" onClick="window.location = '/';">
                Accueil Racine
            </div>
            <div dojoType="dijit.MenuItem" onClick="window.location = '{% url django.contrib.auth.views.logout %}';">
                Logout
            </div>
        </div>
    </div>
    <div dojoType="dijit.PopupMenuBarItem">
        <span>
            Consultation
        </span>
        <div dojoType="dijit.Menu" id="fileMenu">
            {% for project in developpements_projects %}
            <div dojoType="dijit.PopupMenuItem">
                <span>{{ project.label }}</span>
                <div dojoType="dijit.Menu">
                    {% if perms.developpements.can_view_liste %}
                        <div dojoType="dijit.MenuItem" onClick="window.location = '{% url developpements.views.liste project.id %}';">
                            Liste des développements
                        </div>
                    {% endif %}
                    {% if perms.developpements.can_view_versions %}
                        <div dojoType="dijit.MenuItem" onClick="window.location = '{% url developpements.views.versions project.id %}';">
                            Versions
                        </div>
                    {% endif %}
                </div>
            {% endfor %}
            </div>
        </div>
    </div>
    <div dojoType="dijit.PopupMenuBarItem">
        <span>
            Modification
        </span>
        <div dojoType="dijit.Menu" id="editMenu">
            {% if user.is_staff %}
                <div dojoType="dijit.MenuItem" onClick="window.location = '{% url admin:index %}';">
                    Admin
                </div>
            {% endif %}
            {% if perms.developpements.add_developpement %}
                <div dojoType="dijit.MenuItem" onclick="form_request(0);">
                    Ajouter un développement
                </div>
            {% endif %}
            {% if perms.developpements.add_version %}
                <div dojoType="dijit.MenuItem" onClick="window.location = '{% url admin:developpements_version_add %}';">
                    Ajouter une version
                </div>
            {% endif %}
            {% if perms.developpements.add_groupedev %}
                <div dojoType="dijit.MenuItem" onClick="window.location = '{% url admin:developpements_groupedev_add %}';">
                    Ajouter un groupe de développement
                </div>
            {% endif %}
        </div>
    </div>
</div>

<script type="text/javascript">
    function get_project_content(field) {
        var groupe = dijit.byId("id_modify_groupe");
        var version = dijit.byId("id_modify_version_requise");
        dojo.xhrGet({url: "{% url developpements.views.populate_field %}",
                handleAs: "json",
                content: { "project_pk": field.value, },
                load: function (ret) {
                    if (ret.error) {
                        alert(ret.error);
                    }
                    else {
                        dojo.forEach(ret.groupe,
                            function (c) { groupe.addOption(c); });
                        dojo.forEach(ret.version,
                            function (c) { version.addOption(c); });
                    }
                    }});
    }
    function form_request(pk) {
        dojo.xhrGet({url: "{% url developpements.views.modify %}",
                handleAs: "json",
                content: { dev_pk: pk, },
                load: function (ret) {
                    if (ret.error) {
                        alert(ret.error);
                    }
                    else {
                        dojo.place(ret.form, "target_table", "only");
                        dojo.attr("target_form", "itempk", ret.itempk);
                        dojo.parser.parse();
                        dijit.byId("dialog_edit").show();
                    }
                }});
    }
    function form_submit(form) {
        dojo.xhrPost({ url: "{% url developpements.views.modify %}",
                form: form,
                handleAs: "json",
                content: { dev_pk: dojo.attr("target_form", "itempk"), },
                load: function (ret) {
                    if (ret.error) {
                        dojo.place(ret.form, "target_table", "only");
                        dojo.parser.parse();
                    }
                    else {
                        dojo.global.location.reload();
                    }
                }
                });
        return false;
    }
</script>
<div dojoType="dijit.Dialog" id="dialog_edit">
    <form onsubmit="return form_submit(this);" id="target_form">
        <table id="target_table"></table>
    <div dojoType="dijit.form.Button" iconClass="dijitEditorIcon dijitEditorIconSave" type="submit">Valider</div>
    </form>
</div>
